package com.iter.devbox.util;

import java.util.Comparator;

/**
 * 比较对象大小，实现Comparator接口
 * 
 * @author Jimly
 */
public class Person implements Comparator<Person> {

	/**用户年龄*/
	private int age;
	
	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	
	@Override
	public int compare(Person o1, Person o2) {
		if (o1.getAge() > o2.getAge()) {
			return 1;
		} else if (o1.getAge() == o2.getAge()) {
			return 0;
		} else {
			return -1;
		}
	}
	
	public static void main(String[] args) {
		Person p1 = new Person ();
		p1.setAge(20);
		
		Person p2 = new Person();
		p2.setAge(21);
		
		System.out.println(p1.compare(p1, p2));
	}
}
